import { fromJS } from 'immutable'
import { K_INTERVAL_FIVE_MINUTES, STOCK_CHART_ORIGINAL_VIEW } from '../actions/tradeChartAction'
import storageUtils from '../../utils/storageUtils'

export const TRADE_CHART_ACTION = 'trade_chart_action'

const initialState = fromJS({
  stockChartType: STOCK_CHART_ORIGINAL_VIEW,
  currentInterval: storageUtils.getValue(storageUtils.K_LINE_INTERVAL) || K_INTERVAL_FIVE_MINUTES,
  kLineData: null
})

export default (state = initialState, action) => {
  if (action.type === TRADE_CHART_ACTION) {
    return state.merge(action.data)
  }
  return state
}
